#include "LeftChild.h"
#include <commctrl.h>

LeftChild::LeftChild()
{
	m_pInterface = new ToolboxInterface();
}
LeftChild::~LeftChild()
{
	if(m_pInterface)
	{
		delete m_pInterface;
		m_pInterface = NULL;
	}
}

bool LeftChild::Setup(HWND a_parent, HINSTANCE a_hInst, int a_xPos, int a_yPos, int a_width, int a_height, char* a_pWindowName, char* a_pClassName, DWORD a_style)
{
	WNDCLASS wndClass;
	ZeroMemory(&wndClass, sizeof(WNDCLASS));

	wndClass.cbClsExtra = NULL;
	wndClass.cbWndExtra = sizeof(Controller*);
	wndClass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
	wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
	wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wndClass.hInstance = a_hInst;
	wndClass.lpfnWndProc = Controller::WndProc;
	wndClass.lpszMenuName = NULL;
	wndClass.style = CS_DROPSHADOW;
	wndClass.lpszClassName = a_pClassName;

	if(!RegisterClass(&wndClass))
	{
		return false;
	}

	RECT rect;
	GetClientRect(a_parent, &rect);

	m_hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, a_pClassName, a_pWindowName, a_style, a_xPos, a_yPos, a_width, a_height, a_parent, NULL, a_hInst, (LPVOID)this);
	if(m_hWnd == NULL)
	{
		return false;
	}
	UpdateWindow(m_hWnd);
	ShowWindow(m_hWnd, SW_SHOW);

	//Setup the UI
	if(!m_pInterface->Setup(m_hWnd, a_hInst))
	{
		MessageBox(NULL, "Failed to Setup User Interface!", "Error", MB_OK | MB_ICONEXCLAMATION);
		return false;
	}

	return true;
}
void LeftChild::Update()
{
	m_pInterface->Update();
}
void LeftChild::Command(int a_id, int a_cmd, LPARAM a_msg)
{
	if(a_msg != 0)
	{
		if(a_cmd == BN_CLICKED)
		{
			m_pInterface->UpdateControls((HWND)a_msg);
		}
	}
}
void LeftChild::Notify(int a_id, LPARAM a_lParam)
{
	NMHDR* nmhdr = (NMHDR*)a_lParam;
	switch(nmhdr->code)
	{
	case TVN_BEGINLABELEDIT:
		{
			int one = 1;	
		}
		break;
	case TVN_ENDLABELEDIT:
		{
			
		}
		break;
	};
}
